package com.qf.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.mapper.DtsPermissionMapper;
import com.qf.pojo.DtsPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@Service
public class DtsPermissionServiceImpl implements DtsPermissionService{

        @Autowired
        private DtsPermissionMapper permissionMapper;

        /**
         * 根据多个角色id查询权限字符串集合
         * @param roleIds
         * @return
         */
        @Override
        public Set<String> queryByRoleIds(Integer[] roleIds) {
            Set<String> permissions = new HashSet<String>();

            //判断是否有角色参数
            if (roleIds == null || roleIds.length == 0) {
                return permissions;
            }

            //查询数据库
            QueryWrapper<DtsPermission> wapper = new QueryWrapper<>();
            wapper.in("role_id", Arrays.asList(roleIds));
            wapper.eq("deleted", false);
            List<DtsPermission> permissionList = permissionMapper.selectList(wapper);

            for (DtsPermission permission : permissionList) {
                permissions.add(permission.getPermission());
            }

            return permissions;
        }

}
